<template>
	<view class="container">
		<view>
			<uni-popup ref="popup" type="top" background-color="#fff">
				<view class="popup-content">
					<!-- <uni-forms ref="queryForm" :modelValue="queryParams">
						<uni-forms-item label="案件编号" label-width="85">
							<uni-easyinput v-model="queryParams.caseCode" placeholder="案件编号"></uni-easyinput>
						</uni-forms-item>
						<uni-forms-item label="上报时间" label-width="85">
							<uni-datetime-picker v-model="queryParams.reportTime" type="daterange"/>
						</uni-forms-item>
					</uni-forms>
					<view style="display: flex;">
						<button size="mini" class="common-btn other-btn" @click="handleRepeat">重置</button>
						<button size="mini" class="common-btn primary-btn" @click="handleQuery">查询</button>
					</view> -->
					<case-query-form @query="handleQuery"></case-query-form>
				</view>
			</uni-popup>
		</view>
		<view class="uni-list">
			<block v-for="(item, index) in listData" :key="index">
				<view class="list-item">
					<view @click="handleDeal(item)">
						<view class="list-row">
							<view class="list-row-label">案件编号</view>
							<view class="list-row-content">{{item.caseCode}}</view>
						</view>
						<view class="list-row">
							<view class="list-row-label">当前环节</view>
							<view class="list-row-content">{{item.linkName}}</view>
						</view>
						<view class="list-row">
							<view class="list-row-label">案件类型</view>
							<view class="list-row-content">{{item.caseTypeName}}</view>
						</view>
						<view class="list-row">
							<view class="list-row-label">问题描述</view>
							<view class="list-row-content">{{item.caseDesc}}</view>
						</view>
					</view>
					<button class="common-btn" type="warn"
						v-if="item.linkId=='Activity_0kg4yzm'
					  || item.linkId=='Activity_1qee6xl'
					  || item.linkId=='Activity_16i7dua'"
					 size="mini" @click="caseCancelApply(item)">撤销申请授权</button>
				</view>
			</block>
		</view>
		<uni-load-more :status="status" :icon-size="16" :content-text="contentText" />
	</view>
</template>

<script>
	import { getDicts } from "@/api/system/dict/data";
	import { dateUtils } from  '@/utils/util.js';
	import { getHandleCaseList } from '@/api/dums/caw/caseInfo.js'
	import { caseCancelApply } from '@/api/dums/caw/caseSignTransact.js'
	export default {
		data(){
			return {
				queryParams:{
					caseCode:"",
					reportTime:[]
				},
				page:1,
				size:10,
				total:0,
				listData: [],
				reload: false,
				status: 'more',
				adpid: '',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				sourceOptions:[]
			}
		},
		methods:{
			getList() {
				uni.showLoading({
					title:"加载中"
				})
				if (this.total && !this.reload) {
					//说明已有数据，目前处于上拉加载
					this.status = 'loading';
				}
				if(this.reload){
					uni.stopPullDownRefresh();
				}
				this.queryParams.pageSize = this.size;
				this.queryParams.pageNum = this.page;
				getHandleCaseList(this.queryParams).then(res => {
					uni.hideLoading();
					if(res.code == 200){
						let list = res.rows;
						this.total = res.total;
						list.forEach(item => {
							if(item.rptChannelId){
								this.sourceOptions.forEach(opt => {
									if(opt.dictValue == item.rptChannelId){
										item.caseSource = opt.dictLabel;
									}
								})
							}
						})
						this.listData = this.reload ? list : this.listData.concat(list);
						this.reload = false;
						//判断是否最后一页
						if(this.size*this.page>=res.total){
							this.status="noMore"
						}
					}
				})
			},
			handleQuery(params){
				/* if(this.queryParams.reportTime &&　this.queryParams.reportTime.length>0){
					let params = {
						"rptTimeStrStart":this.queryParams.reportTime[0]+" 00:00:00",
						"rptTimeStrEnd":this.queryParams.reportTime[1]+" 23:59:59"
					}
					this.queryParams.params = params;
				} */
				this.queryParams = params;
				this.page = 1;
				this.reload = true;
				this.listData = [];
				this.getList();
				this.$refs.popup.close()
			},
			handleRepeat(){
				this.queryParams = {};
			},
			handleDeal(item){
				console.log(item.caseId);
				uni.navigateTo({
					url:'../case_detail/index?caseId='+item.caseId
				})
			},
			caseCancelApply(data){
				console.log(data);
				uni.showModal({
					content:"是否确认撤销申请授权？",
					confirmText:"确定",
					cancelText:"取消",
					success(e) {
						console.log(e)
						if(e.confirm){
							caseCancelApply({caseId: data.caseId}).then(res=>{
								if(res.code=='200'){
									this.$modal.msgSuccess(res.msg);
								}else{
									this.$modal.msgError(res.msg);
								}
								this.getList();
							 });
						}
					}
				})
			}
		},
		
		onLoad() {
			this.page = 1;
			this.reload = true;
			this.listData = [];
			this.getList();
			//问题来源
			getDicts("case_source").then(response => {
				this.sourceOptions = response.data;
			});
		},
		onNavigationBarButtonTap : function (e) {
			this.$refs.popup.open()
		},
		onPullDownRefresh(){
			this.page = 1;
			this.reload = true;
			this.listData = [];
			this.getList();
		},
		onReachBottom(){
			this.page++;
			if(this.listData.length < this.total){
				this.status = 'more';
			}else{
				this.status = 'noMore';
				return;
			}
			this.getList();
		}
	}
</script>

<style lang="scss">
	.popup-content {
		padding: 15px;
		height: 500px;
		background-color: #fff;
	}
	.list-item{
		padding: 16px;
		border-bottom: 1px solid #F1F1F1;
	}
	.list-row{
		display: flex;
		padding-bottom: 10px;
	}
	.list-row-label{
		font-family: MicrosoftYaHei;
		font-size: 14px;
		font-weight: normal;
		line-height: 17px;
		letter-spacing: 0px;
		color: #9DA0AA;
		width: 25%;
	}
	.list-row-content{
		font-family: MicrosoftYaHei;
		font-size: 14px;
		font-weight: normal;
		line-height: 17px;
		letter-spacing: 0px;
		width: 75%;
		color: #353B50;
		white-space:nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
	}
	.nav-btn{
		margin-right: 15px;
	}
</style>